using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace SpriteAnimations.Graphics.Animations
{
    class LerpColorAnimation : SpriteAnimation
    {
        //
        // Fields
        //
        private Color m_C1, m_C2;
        private TimeSpan m_InterpolateLength;

        //
        // Constructors
        //
        public LerpColorAnimation(Color c1, Color c2, TimeSpan InterpolateLength)
        {
            m_C1 = c1;
            m_C2 = c2;
            m_InterpolateLength = InterpolateLength;
        }

        //
        // Virtual Methods
        //
        public override void Animate(TimeSpan gameTime, SpriteParameters animatedParameters)
        {
            double tmp = (gameTime.TotalMilliseconds % m_InterpolateLength.TotalMilliseconds) / m_InterpolateLength.TotalMilliseconds;

            byte a = (byte)(m_C1.A + (m_C2.A - m_C1.A) * tmp);
            byte r = (byte)(m_C1.R + (m_C2.R - m_C1.R) * tmp);
            byte g = (byte)(m_C1.G + (m_C2.G - m_C1.G) * tmp);
            byte b = (byte)(m_C1.B + (m_C2.B - m_C1.B) * tmp);

            animatedParameters.Tint = new Color(r, g, b, a);
        }
    }
}
